package com.idanchuang.component.redis.warmup;

import com.idanchuang.component.redis.util.DRedisLocks;
import com.idanchuang.component.redis.util.RedisLimits;
import com.idanchuang.component.redis.util.RedisUtil;
import com.idanchuang.sun.client.common.health.WarmUp;
import com.idanchuang.sun.client.common.health.WarmUpProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import java.time.Clock;
import java.time.Instant;

/**
 * @author yjy
 * Created at 2021/9/15 5:18 下午
 */
public class ComponentRedisWarmUp {

    @Autowired
    private RedisUtil redisUtil;

    @WarmUp
    public void warmUpRedisUtil() {
        // warm up normal operation
        String key = "warmUpRedisUtil:" + System.nanoTime();
        redisUtil.set(key, "warmup by component-redis");
        redisUtil.del(key);
    }

    @WarmUp
    public void warmUpRedisLock() {
        // warm up lock
        DRedisLocks.runWithLock("warmUpRedisLock:" + System.currentTimeMillis(), () -> {});
    }

    @WarmUp
    public void warmUpRedisLimit() {
        // warm up lock
        RedisLimits.require("warmUpRedisLimit:" + System.currentTimeMillis(), 10, 1);
    }

}
